package v1.chapter9.treeSet;

import java.util.Objects;

public class Item implements Comparable<Item> {

	private String description;
	private int partNumber;

	public Item(String aDescription, int aPartNumber) {
		description = aDescription;
		partNumber = aPartNumber;
	}

	public String getDescription() {
		return description;
	}

	public String toString() {
		return "[description=" + description + ", partNumber=" + partNumber + "]";
	}

	public int hashCode() {
		return Objects.hash(description, partNumber);
	}

	public int compareTo(Item o) {
		int diff = Integer.compare(partNumber, o.partNumber);
		return diff != 0 ? diff : description.compareTo(o.description);
	}
}
